package com.zhiling.www.controller;

import com.zhiling.www.entity.Result;
import com.zhiling.www.entity.User;
import com.zhiling.www.service.UserService;
import com.zhiling.www.util.JwtUtils;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    //用户登录验证
    @RequestMapping("/login")
    public Result login(@RequestBody User user){

        return userService.login(user);
    }

    //用户注册
    @PostMapping("/register/{code}")
    public Result register(@PathVariable String code,@RequestBody User user){
        return userService.register(user,code);
    }

    //加载当前用户信息
    @GetMapping("/loaduser")
    public Result loadUser(HttpServletRequest request){
        String token = request.getHeader("token");
        return userService.loadUser(token);
    }

    //根据用户id查询用户信息
    @PostMapping("/finduser")
    public Result findUser(Integer userId){
        return userService.findUser(userId);
    }

    //根据用户id更新余额
    @PostMapping("/updatamoney")
    public Result updataMoney(@RequestBody User user){
        return userService.updateMoney(user);
    }

    //注销
    @GetMapping("/logout")
    public Result logout(HttpServletRequest request){
        String token = request.getHeader("token");
        return userService.logout(token);
    }

    //发送手机验证码
    @GetMapping("/getCode/{phone}")
    public Result getCode(@PathVariable String phone){
        return userService.getCode(phone);
    }

    //身份验证
    @PostMapping("/identity")
    public Result identity(@RequestBody User user){
        return userService.identity(user);
    }

    //验证用户是否实名认证
    @GetMapping("/checkCard")
    public Result checkCard(HttpServletRequest request){
        String token = request.getHeader("token");
        return userService.checkCard(token);
    }

    //充值提现
    @GetMapping("/alterMoney/{money}")
    public Result alterMoney(@PathVariable double money,HttpServletRequest request){
        String token = request.getHeader("token");
        return userService.alterMoney(money,token);
    }

    //加载充值记录信息
    @GetMapping("/record")
    public Result record(int page,int pageSize,int type,HttpServletRequest request){
        String token = request.getHeader("token");
        return userService.record(page,pageSize,type,token);
    }
}
